<?php
/* 
* @Author: LDF QQ 47121862
* @Date:   2014-06-09 23:10:42
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-06-12 17:41:30
*/
class XilieCommentControl extends ConfigControl{
	//添加评论ajax
	function add(){
		if(!$_SESSION['user']['uid']) $s=0;
		// 组合评论数据
		$data = $this->formHandle();
		if(M('xcomment')->add($data)){
			M('xilie')->inc('comments','xid='.$data['xid'],1); //文章评论数更新
			$s=1;
			$msg='发表评论成功...';
		}else{
			$s=0;
			$msg='发表评论失败...';
		}
		$data['addtime']=date('Y-m-d H:i:s',$data['addtime']);
		$this->lAjax($s,$msg,$data);
	}
	// 组合评论数据
	private function formHandle(){
		$data = array(
			'content'=>Q('content'),
			'addtime'=>time(),
			'uid'=>$_SESSION['user']['uid'],
			'xid'=>Q('xid',0,'intval')
		);
		return $data;
	}
	//ajax
	private function lAjax($state=null,$msg=null,$data=null){
		echo json_encode(array('state'=>$state,'msg'=>$msg,'data'=>$data));die;
	}
}
